<?php
declare (strict_types=1);

namespace app\admin\model;

use app\common\model\BaseModel;

/**
 * 后台模型基类
 * Class AdminBaseModel
 * @package app\admin\model
 */
abstract class AdminBaseModel extends BaseModel
{
    // 查询后
    public static function onAfterRead($info)
    {
        $model = new static();
        $charset = $model->getConfig('charset');
        if($charset == 'latin1') {
            foreach ($info->getData() as $key => $value){
                if($value) $info->set($key, gbkToUtf8($value));
            }
        }
    }

    // 写入前
    public static function onBeforeWrite($data)
    {
        $model = new static();
        $charset = $model->getConfig('charset');
        if($charset == 'latin1') {
            foreach ($data as $key => $value){
                if($value) $data[$key] = utf8ToGbk($value);
            }
        }
    }
}
